﻿using MyFirstWPF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyFirstWPF.View
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑  ： 我的卡片
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        private TaskInfo task;
        //卡片初始化
        public UserControl1()
        {
            InitializeComponent();
        }

        public UserControl1(TaskInfo task)
        {
            InitializeComponent();
            this.task = task;
            tbName.Text = task.Name;
            date.Text = task.StartTime;
            showName.Text = task.Name;
            showDescription.Text = "  "+task.Description;
            showStartTime.Text = "  "+task.StartTime;
            showEndTime.Text = "  "+task.EndTime;
            
        }

        //删除按钮
        private void Button_Click(object sender, RoutedEventArgs e)
        {
           using (var db = new StudyPlanDb(Page1.dbPath))
            {
                db.Tasks.Where(x => x.Id == task.Id).Delete();
            }
            WrapPanel p = (WrapPanel)Parent;
            p.Children.Remove(this);
        }
   
    }
}
